<?php

class Admin_SettingsAction extends BlogAdminBaseAction
{
    public function executeRead(AgaviRequestDataHolder $rd)
    {
        return 'Input';
    }
    
    public function executeWrite(AgaviRequestDataHolder $rd)
    {
        $params = $rd->getParameters();
        $vm = $this->getContainer()->getValidationManager();
        
        // try to save
        try {
            WereWordConfig::set('blog.name', $params['blog_name']);
            WereWordConfig::set('blog.index_posts_count', $params['blog_index_posts_count']);
            WereWordConfig::set('blog.owner_login', $params['owner_login']);
            WereWordConfig::set('blog.owner_name', $params['owner_display_name']);
            WereWordConfig::set('blog.owner_email', $params['owner_email']);
            WereWordConfig::set('blog.counters_analytics', $params['counters_analytics']);
            WereWordConfig::set('blog.applet.links.links_list', $params['links_applet_links']);
            WereWordConfig::set('blog.openid_server', $params['openid_server']);
            WereWordConfig::set('blog.openid_server_delegate', $params['openid_server_delegate']);
            if (isset($params['password1']) && $params['password1'] !== '') {
                $pass_hash = BlogUser::genPasswordHash($params['password1']);
                WereWordConfig::set('blog.owner_password', $pass_hash);
            }
        } catch (PropelException $e) {
            $vm->setError('general', 'Unable to save: ' . $e);
            return 'Error';
        }
        // clear whole cache
        AgaviExecutionFilter::clearCache();
        return 'Success';
    }
    
	/**
	 * Returns the default view if the action does not serve the request
	 * method used.
	 *
	 * @return     mixed <ul>
	 *                     <li>A string containing the view name associated
	 *                     with this action; or</li>
	 *                     <li>An array with two indices: the parent module
	 *                     of the view to be executed and the view to be
	 *                     executed.</li>
	 *                   </ul>
	 */
	public function getDefaultViewName()
	{
		return 'Success';
	}
}


function test1($p)
{
    /* @var $p Admin_SettingsAction */
    $p->
    var_dump($p);
}

function test2()
{
    $x = new DateTime();
    test1($x); 
}
?>